﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Account_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Login_Click(object sender, EventArgs e)
    {
        try
        {
            if (txt_userName.Value.Length == 0 || txt_userName.Value.Length < 4 || txt_password.Value.Length == 0)
            {
                Common.AlertMessage("请输入用户名或密码！");
                return;
            }

            if (string.Equals(txtValidate.Value.ToLower(), Session["CAPTCHATEXT"] == null ? txtValidate.Value.ToLower() :
                Session["CAPTCHATEXT"].ToString().ToLower()) == false)
            {
                Common.AlertMessageAndRedirect("验证码错误！", ResolveUrl("~/Account/login.aspx"));
                return;
            }

            using (DataTable dt = DataHandler.Current.UserLogin(txt_userName.Value.Trim(), txt_password.Value.Trim()))
            {
                if (!Common.DtIsNullOrEmpty(dt))
                {
                    int ret = int.Parse(dt.Rows[0]["ret"].ToString());
                    if (ret == 1)
                    {
                        PageHelper.Current.SetCookie(dt);
                        Response.Redirect("~/Index.aspx", false);

                    }
                    else
                    {
                        Common.AlertMessageAndRedirect("用户名或密码错误",
                               ResolveUrl("~/Account/login.aspx"));
                    }
                }
            }
        }
        catch(Exception ex)
        {
            throw ex;
        }
    }
}